package com.ruoyi.remark.controller;

import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.anno.UserCheck;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.remark.domain.BoleRemarkProject;
import com.ruoyi.remark.service.IBoleRemarkProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标注提交记录Controller
 * 
 * @author wujiale
 * @date 2025-04-19
 */
@RestController
@RequestMapping("/remark/project")
public class BoleRemarkProjectController extends BaseController
{
    @Autowired
    private IBoleRemarkProjectService boleRemarkProjectService;
    @GetMapping(value = {"/batch", "/batch/{ids}"})
    public AjaxResult selectBoleRemarkProjectByIds(@PathVariable(required = false) List<Long> ids) {

        if (ids == null){
            return success("无数据");
        }
        List<BoleRemarkProject> list = boleRemarkProjectService.selectBoleRemarkProjectByIds(ids);
        return success(list);
    }
//被驳回之后要做修改
    @Log(title = "标注提交记录", businessType = BusinessType.UPDATE)
    @PutMapping("/updatefalse")
    public AjaxResult updateFalse(@RequestBody BoleRemarkProject boleRemarkProject)
    {
        if(!Objects.equals(boleRemarkProject.getUserId(), SecurityUtils.getUserId())){
            return error("您没有权限修改");
        }
        boleRemarkProject.setStatus("0");
        return toAjax(boleRemarkProjectService.updateBoleRemarkProject(boleRemarkProject));
    }
    /**
     * 审核通过标注提交记录
     */
    @PreAuthorize("@ss.hasPermi('remark:project:edit')")
    @Log(title = "标注提交记录", businessType = BusinessType.UPDATE)
    @PutMapping("/check")
    public AjaxResult check(@RequestBody BoleRemarkProject boleRemarkProject)
    {
        return toAjax(boleRemarkProjectService.checkRemarkProject(boleRemarkProject));

    }

    @GetMapping("/user/list")
    public TableDataInfo listUser(BoleRemarkProject boleRemarkProject)
    {
        boleRemarkProject.setUserId(SecurityUtils.getUserId());
        startPage();
        List<BoleRemarkProject> list = boleRemarkProjectService.selectBoleRemarkProjectList(boleRemarkProject);
        return getDataTable(list);
    }
    @GetMapping("/user/{submitId}")
    public AjaxResult getInfoUser(@PathVariable("submitId") Long submitId)
    {
        return success(boleRemarkProjectService.selectBoleRemarkProjectBySubmitId(submitId));
    }
    //用户提交
//    @PostMapping("/user")
//    public AjaxResult addUser(@RequestBody BoleRemarkProject boleRemarkProject)
//    {
//        boleRemarkProject.setUserId(SecurityUtils.getUserId());
//        boleRemarkProject.setWorkload(0L);
//        boleRemarkProject.setStatus("0");
//        return toAjax(boleRemarkProjectService.userAdd(boleRemarkProject));
//    }

    @UserCheck(name = "删除操作 进行用户检查")
    @DeleteMapping("/user/{submitIds}/{userId}")

    public AjaxResult removeUser(@PathVariable Long[] submitIds, @PathVariable Long userId)
    {
        return toAjax(boleRemarkProjectService.deleteBoleRemarkProjectBySubmitIds(submitIds));
    }
    /**
     * 查询标注提交记录列表
     */
    @PreAuthorize("@ss.hasPermi('remark:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoleRemarkProject boleRemarkProject)
    {
        startPage();
        List<BoleRemarkProject> list = boleRemarkProjectService.selectBoleRemarkProjectList(boleRemarkProject);
        return getDataTable(list);
    }

    /**
     * 导出标注提交记录列表
     */
    @PreAuthorize("@ss.hasPermi('remark:project:export')")
    @Log(title = "标注提交记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoleRemarkProject boleRemarkProject)
    {
        List<BoleRemarkProject> list = boleRemarkProjectService.selectBoleRemarkProjectList(boleRemarkProject);
        ExcelUtil<BoleRemarkProject> util = new ExcelUtil<BoleRemarkProject>(BoleRemarkProject.class);
        util.exportExcel(response, list, "标注提交记录数据");
    }

    /**
     * 获取标注提交记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('remark:project:query')")
    @GetMapping(value = "/{submitId}")
    public AjaxResult getInfo(@PathVariable("submitId") Long submitId)
    {
        return success(boleRemarkProjectService.selectBoleRemarkProjectBySubmitId(submitId));
    }

    /**
     * 新增标注提交记录
     */
    @PreAuthorize("@ss.hasPermi('remark:project:add')")
    @Log(title = "标注提交记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoleRemarkProject boleRemarkProject)
    {
        return toAjax(boleRemarkProjectService.insertBoleRemarkProject(boleRemarkProject));
    }

    /**
     * 修改标注提交记录
     */
    @PreAuthorize("@ss.hasPermi('remark:project:edit')")
    @Log(title = "标注提交记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoleRemarkProject boleRemarkProject)
    {
        return toAjax(boleRemarkProjectService.updateBoleRemarkProject(boleRemarkProject));
    }

    /**
     * 删除标注提交记录
     */
    @PreAuthorize("@ss.hasPermi('remark:project:remove')")
    @Log(title = "标注提交记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{submitIds}")
    public AjaxResult remove(@PathVariable Long[] submitIds)
    {
        return toAjax(boleRemarkProjectService.deleteBoleRemarkProjectBySubmitIds(submitIds));
    }
}
